//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include "identified.h"
#include "idgenerator.h"
//
Identified::Identified(QObject *p_parent)
:
   QObject(p_parent)
{
   /*   if(p_new_id)
         id=IdGenerator::get()->generate();
      else
         id=IdGenerator::invalid_id;*/
}
//
Id Identified::get_id()const
{
   return id;
}
void Identified::set_id(Id p_id)
{
   id=p_id;
}
//
QDataStream &operator<<(QDataStream &p_stream,const Identified *p_ptr)
{
   if(p_ptr)
   {
      p_stream<<true;
      p_stream<<p_ptr->get_id();
   }
   else
   {
      p_stream<<false;
   }
   return p_stream;
}
RestoreStream &operator>>(RestoreStream &p_stream,Identified *&p_ptr)
{
   bool nonnull;p_stream>>nonnull;
   if(nonnull)
   {
      Id id;
      p_stream>>id;
      IdDictionary::const_iterator found=p_stream.get_dictionary().find(id);
      if(found==p_stream.get_dictionary().end())
         throw(RestoreError("id not found in dictionary at Identified::restore_ptr_identified"));
      else
         p_ptr=found.value();
   }
   else
      p_ptr=0;
   return p_stream;
}
